//
//  KBTopView.swift
//  KimboWeiBoSwift
//
//  Created by kimbo on 15/12/20.
//  Copyright © 2015年 kimbo. All rights reserved.
//

import UIKit
import SDWebImage

class KBTopView: UIView {

    // MARK: - 属性
    var status: KBStatus? {
        didSet {
            /* 头像 */
            if let profile_image_url = status?.user?.profile_image_url {
                iconView.sd_setImageWithURL(NSURL(string: profile_image_url), placeholderImage: UIImage(named: "avatar"))
            }
            /* 名称 */
            nameLabel.text = status?.user?.screen_name
            
            /* 时间 */
            timeLabel.text = "刚刚"
            
            /* 来源 */
            sourceLabel.text = "中南海"
            
            /* 会员等级 */
            vipView.image = status?.user?.mbrankImage
            
            /* 认证图标 */
            verifiedView.image = status?.user?.verifiedImage
        }
    }

    override init(frame: CGRect) {
        super.init(frame: frame)
        
        //设置UI
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    /// 设置UI
    private func setupUI() {
        addSubview(separatorView)
        addSubview(iconView)
        addSubview(nameLabel)
        addSubview(timeLabel)
        addSubview(sourceLabel)
        addSubview(vipView)
        addSubview(verifiedView)
        
        //添加约束
        /* 分割线 */
        separatorView.ff_AlignInner(type: ff_AlignType.TopLeft, referView: self, size: CGSize(width: UIScreen.mainScreen().bounds.width, height: 10))
        /* 头像 */
        iconView.ff_AlignVertical(type: ff_AlignType.BottomLeft, referView: separatorView, size: CGSize(width: 35, height: 35), offset: CGPoint(x: 8, y: 8))
        /* 名称 */
        nameLabel.ff_AlignHorizontal(type: ff_AlignType.TopRight, referView: iconView, size: nil, offset: CGPoint(x: 8, y: 0))
        /* 时间 */
        timeLabel.ff_AlignHorizontal(type: ff_AlignType.BottomRight, referView: iconView, size: nil, offset: CGPoint(x: 8, y: 0))
        /* 来源 */
        sourceLabel.ff_AlignHorizontal(type: ff_AlignType.CenterRight, referView: timeLabel, size: nil, offset: CGPoint(x: 8, y: 0))
        /* 会员等级 */
        vipView.ff_AlignHorizontal(type: ff_AlignType.CenterRight, referView: nameLabel, size: CGSize(width: 14, height: 14), offset: CGPoint(x: 8, y: 0))
        /* 认证图标 */
        verifiedView.ff_AlignInner(type: ff_AlignType.BottomRight, referView: iconView, size: CGSize(width: 17, height: 17), offset: CGPoint(x: 8.5, y: 8.5))
    }
    
    
    // MARK: - 懒加载
    /* 分割线 */
    private lazy var separatorView: UIView = {
       let separatorView = UIView()
        
        separatorView.backgroundColor = UIColor(white: 0.95, alpha: 1)
        
        return separatorView
    }()
    
    /* 头像 */
    private lazy var iconView: UIImageView = UIImageView(image: UIImage(named: "avatar"))

    /* 名称 */
    private lazy var nameLabel: UILabel = UILabel(color: UIColor.darkGrayColor(), fontSize: 14)
    
    /* 时间 */
    private lazy var timeLabel: UILabel = UILabel(color: UIColor.orangeColor(), fontSize: 9)
    
    /* 来源 */
    private lazy var sourceLabel: UILabel = UILabel(color: UIColor.lightGrayColor(), fontSize: 9)
    
    /* 会员等级 */
    private lazy var vipView: UIImageView = UIImageView(image: UIImage(named: "common_icon_membership_expired"))
    
    /* 认证图标 */
    private lazy var verifiedView: UIImageView = UIImageView(image: nil)
    
    
}


